Imports Microsoft.VisualBasic
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Windows.Forms

Imports System.ComponentModel.Design
Imports System.Windows.Forms.Design

Imports Phoenix.Tools.General

Namespace Phoenix.Tools
  Public Class LineFrame : Inherits System.Windows.Forms.Control
	#Region "Class constants"
	Public Enum TLineStyle
	  Horizontal
	  Vertical
	End Enum
	#End Region

	#Region "Class members"
	Shared Private m_pntStart As Point = New Point(0, 1)
	Shared Private m_gdi As GDIUtils = New GDIUtils()

	Private m_pntEnd As Point = New Point(0, 1)
	Private m_enStyle As TLineStyle = TLineStyle.Horizontal
	#End Region

	#Region "Class Properties"
	<Category("Appearance"), DefaultValue(GetType(TLineStyle), "Horizontal"), Description("GET/SET style of line")> _
	Public Property LineStyle() As TLineStyle
	  Get
		Return m_enStyle
	  End Get
	  Set
		If Value <> m_enStyle Then
		  m_enStyle = Value
		  OnLineStyleChanged()
		End If
	  End Set
	End Property

	Protected Overrides ReadOnly Property DefaultSize() As System.Drawing.Size
	  Get
		If m_enStyle = TLineStyle.Horizontal Then
		  Return New Size(75, 4)
		Else
		  Return New Size(4, 75)
		End If
	  End Get
	End Property
	#End Region

	#Region "Class Initialize/Finilize code"
	Public Sub New()
	  Dim styleTrue As ControlStyles = ControlStyles.ResizeRedraw Or ControlStyles.DoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or ControlStyles.UserPaint Or ControlStyles.FixedHeight

	  Dim styleFalse As ControlStyles = ControlStyles.SupportsTransparentBackColor Or ControlStyles.Selectable

	  SetStyle(styleTrue, True)
	  SetStyle(styleFalse, False)

	  MyBase.Size = New Size(75, 4)
	  MyBase.TabStop = False

	  m_gdi.Dark = m_gdi.DarkDark
	End Sub

	Protected Overrides Overloads Sub Dispose(ByVal disposing As Boolean)
	  If disposing = True Then
		'm_gdi.Dispose();
	  End If

	  MyBase.Dispose(disposing)
	End Sub
	#End Region

	#Region "Class Overrides"
	Protected Overridable Sub OnLineStyleChanged()
	  SetStyle(ControlStyles.FixedHeight, (m_enStyle = TLineStyle.Horizontal))
	  SetStyle(ControlStyles.FixedWidth, (m_enStyle = TLineStyle.Vertical))

	  m_pntEnd.X = 1
	  m_pntEnd.Y = Height

	  Invalidate()
	End Sub

	Protected Overrides Sub OnSizeChanged(ByVal e As System.EventArgs)
	  MyBase.OnSizeChanged(e)

	  If m_enStyle = TLineStyle.Horizontal Then
		MyBase.Size = New Size(Size.Width, 4)
		m_pntEnd.X = Width
		m_pntEnd.Y = 1
	  Else
		MyBase.Size = New Size(4, Size.Height)
		m_pntEnd.X = 1
		m_pntEnd.Y = Height
	  End If
	End Sub

	Protected Overrides Sub OnPaint(ByVal pe As PaintEventArgs)
	  m_gdi.Draw3DLine(pe.Graphics,IIf((m_enStyle = TLineStyle.Horizontal), m_pntStart, New Point(1, 0)), m_pntEnd)
	End Sub
	#End Region

  End Class
End Namespace